#include "widget.h"
#include "ui_widget.h"
void Widget::Widget::on_b1_clicked()
{
    a += "1";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b2_clicked()
{
    a += "2";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b3_clicked()
{
    a += "3";
    this->ui->lcd->setText(a);
}


void Widget::Widget::on_b4_clicked()
{
    a += "4";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b5_clicked()
{
    a += "5";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b6_clicked()
{
    a += "6";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b7_clicked()
{
    a += "7";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b8_clicked()
{
    a += "8";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_b9_clicked()
{
    a += "9";
    this->ui->lcd->setText(a);
}

void Widget::on_b0_clicked()
{
    a += "0";
    this->ui->lcd->setText(a);
}

void Widget::Widget::on_bAC_clicked()
{
    a.clear();
    this->ui->lcd->setText("0");
}

void Widget::on_bPlus_clicked()
{
    b.insert(0,a);
    a.clear();
    b.insert(1,"+");
    this->ui->lcd->setText(a);
}
void Widget::on_bSub_clicked()
{
    b.insert(0,a);
    a.clear();
    b.insert(1,"-");
    this->ui->lcd->setText(a);
}

void Widget::on_bMul_clicked()
{
    b.insert(0,a);
    a.clear();
    b.insert(1,"*");
    this->ui->lcd->setText(a);
}

void Widget::on_bDiv_clicked()
{
    b.insert(0,a);
    a.clear();
    b.insert(1,"/");
    this->ui->lcd->setText(a);
}

void Widget::on_bEqu_clicked()
{
    if(!a.isEmpty() && !b.isEmpty())
    {
        b.insert(2,a);
        int ans = 0;
        if(b.at(1) == "+")
        {
            ans = QString(b.at(0)).toInt() + QString(b.at(2)).toInt();
            ui->lcd->setText(QString::number(ans));
        }
        else if(b.at(1) == "-")
        {
            ans = QString(b.at(0)).toInt() - QString(b.at(2)).toInt();
            ui->lcd->setText(QString::number(ans));
        }
        else if(b.at(1) == "*")
        {
            ans = QString(b.at(0)).toInt() * QString(b.at(2)).toInt();
            ui->lcd->setText(QString::number(ans));
        }
        else if(b.at(1) == "/")
        {
            ans = QString(b.at(0)).toInt() / QString(b.at(2)).toInt();
            ui->lcd->setText(QString::number(ans));
        }
        a = QString::number(ans);
        b.clear();
    }
    else
    {
        b.insert(0,a);
        a.clear();
    }
}


